/*
 * Copyright 2011 Alibaba.com All right reserved. This software is the
 * confidential and proprietary information of Alibaba.com ("Confidential
 * Information"). You shall not disclose such Confidential Information and shall
 * use it only in accordance with the terms of the license agreement you entered
 * into with Alibaba.com.
 */
package com.goldplusgold.network.lib;


import com.goldplusgold.network.lib.proxy.ProxyInvocationHandler;

/**
 * Dynamic Proxy Factory, to get the rawapi's proxy
 *
 * @author guangming.chen 2013-7-28 下午02:57:33
 */
public class ApiProxyFactory {

    private static ApiProxyFactory sApiProxyFactory;


    public synchronized static ApiProxyFactory getInstance() {
        if (sApiProxyFactory == null) {
            sApiProxyFactory = new ApiProxyFactory();
        }
        return sApiProxyFactory;
    }

    public ApiProxyFactory() {
    }


    /**
     * @param clazz
     * @param <T>
     * @return
     */
    @SuppressWarnings("unchecked")
    public static <T> T getProxy(Class<T> clazz) {
        ProxyInvocationHandler proxyHandler = new ProxyInvocationHandler();
        return (T) proxyHandler.bind(clazz);
    }
}
